import random
import hashlib
from datetime import datetime

''' 随机生成指定长度字符串 '''
def create_nonce_str(length = 6):
    chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    return "".join(random.sample(chars, length))

''' md5加密 '''
def md5(str):
    md5 = hashlib.md5()
    md5.update(str.encode('utf-8'))
    return md5.hexdigest()

''' 创建用户密码 '''
def create_password(password, salt):
    return md5(md5(password) + salt)

def create_order_sn():
    now_time = datetime.now().strftime("%Y%m%d%H%M%S")
    return "sn{0}{1}".format(now_time, random.randint(10000, 99999))

if __name__ == "__main__":
    pass
    # print(create_order_sn())